package com.flowplan.entity;

import com.flowplan.entity.enums.TodoStatus;
import com.flowplan.entity.enums.Priority;
import com.flowplan.entity.enums.TodoType;
import jakarta.persistence.*;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.AllArgsConstructor;
import lombok.experimental.SuperBuilder;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;

/**
 * 待办任务实体类
 */
@Entity
@Table(name = "todo")
@Data
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = true)
public class Todo extends BaseEntity {
    
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    
    /**
     * 关联项目ID
     */
    @Column(name = "project_id", insertable = false, updatable = false)
    private Long projectId;
    
    /**
     * 关联项目
     */
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "project_id")
    private Project project;
    
    /**
     * 待办标题
     */
    @Column(name = "title", nullable = false, length = 200)
    private String title;
    
    /**
     * 待办描述
     */
    @Column(name = "description", columnDefinition = "TEXT")
    private String description;
    
    /**
     * 任务状态
     */
    @Enumerated(EnumType.STRING)
    @Column(name = "status", nullable = false)
    private TodoStatus status = TodoStatus.TODO;
    
    /**
     * 优先级
     */
    @Enumerated(EnumType.STRING)
    @Column(name = "priority")
    private Priority priority = Priority.MEDIUM;
    
    /**
     * 任务类型
     */
    @Enumerated(EnumType.STRING)
    @Column(name = "todo_type", nullable = false)
    private TodoType todoType;
    
    /**
     * 负责人ID
     */
    @Column(name = "assignee_id", insertable = false, updatable = false)
    private Long assigneeId;
    
    /**
     * 负责人
     */
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "assignee_id")
    private SysUser assignee;
    
    /**
     * 报告人ID
     */
    @Column(name = "reporter_id", insertable = false, updatable = false)
    private Long reporterId;
    
    /**
     * 报告人
     */
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "reporter_id")
    private SysUser reporter;
    
    /**
     * 到期时间
     */
    @Column(name = "due_date")
    private LocalDateTime dueDate;
    
    /**
     * 预估工时
     */
    @Column(name = "estimated_hours", precision = 5, scale = 2)
    private BigDecimal estimatedHours;
    
    /**
     * 实际工时
     */
    @Column(name = "actual_hours", precision = 5, scale = 2)
    private BigDecimal actualHours;
    
    /**
     * 关联的Excel计划列表
     */
    @OneToMany(mappedBy = "todo", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
    private List<ExcelTodoRel> excelRels;
    
    /**
     * 相关笔记列表
     */
    @OneToMany(mappedBy = "todo", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
    private List<Note> notes;
}